package com.yl.ydk.ui.adapter

import android.widget.ImageView
import com.yl.ydk.R
import com.yl.ydk.bean.SiteAricleBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder


class SiteAricleAdapter(data: MutableList<SiteAricleBean.DataX>?) :
    BaseQuickAdapter<SiteAricleBean.DataX, BaseViewHolder>(
        R.layout.item_sitearicle,
        data
    ) {

    override fun convert(helper: BaseViewHolder?, item: SiteAricleBean.DataX?) {
        var ivItem: ImageView? = null
        helper?.let {
            it.setText(R.id.tvName, item?.title)
            ivItem = it.getView<ImageView>(R.id.ivItem)
            if (it.position % 2 == 0) {
                ivItem?.setBackgroundResource(R.drawable.icon_sitearicle_item_n)
            } else {
                ivItem?.setBackgroundResource(R.drawable.icon_sitearicle_item_p)
            }
            it.itemView.setOnClickListener {
               onItemClick?.onListItemClick(item)
            }
        }
    }

    private var onItemClick: onListItemClick? = null

    interface onListItemClick {
        fun onListItemClick(item: SiteAricleBean.DataX?)
    }

    fun onListItemClick(onListItemClick: onListItemClick?) {
        this.onItemClick = onListItemClick
    }

}

